<template>
	<div class="noticeFrame" @click="toNoticeDetail($event,notice.id)">
		<div class="noticeMsg">
			<div class="noticeName">{{notice.title}}</div>
			<div class="tip">培训时间：{{notice.trainBeginTime}} 至 {{notice.trainEndTime}}</div>
			<div class="tip">主办单位：{{notice.organizerName}}</div>
		</div>
		<div class="noticeFooter">
			<div class="in-apply">{{show ? '正在报名' : ''}}</div>
      <Buttons :buttons="buttons" @toSignUp="toSignUp(notice.id)" @none="''"></Buttons>
		</div>
	</div>
</template>

<script>
	import config from "@/utils/config.js";
	import {uploadFile } from "@/utils/request";
	export default {
		name: "noticeFrame",
		props: ['notice'],
		data() {
			return {
				// notice: {
				// 	id: 1,
				// 	title: "关于企业管理", //标题
				// 	modeName: "线下培训", //培训方式  
				// 	trainBeginTime: "2020-05-01 20:00:00", // 培训开始时间
				// 	trainEndTime: "2020-05-01 21:00:00", // 培训开始时间
				// 	beginDate: "2020-05-01", // 报名开始日期
				// 	endDate: "2020-05-01", // 报名开始日期
				// 	organizerName: "裕华区宣传部", // 主办单位
				// 	address: "地址" // 地址
				// }
			}
		},
		computed: {
			show() {
				let today = new Date()
				return new Date(this.notice.beginDate + " 00:00:00") <= today && new Date(this.notice.endDate + " 23:59:59") > today
			},
      buttons(){
        if(this.notice.isApply == 1){
          return [{text:"已报名",type:"normal-hover",size:"s",method:"none"}]
        }else {
          return [{text:"立即报名",type:"normal-hover",size:"s",method:"toSignUp"}]
        }
      }
		},
		methods:{
			// 跳转视频培训详情页
			toNoticeDetail($event,id) {
        if($event.target.nodeName == 'DIV'){
				  this.$router.push({ path: '/training/trainingNotice/trainNoticeDetail', query: { id } });
        }
			},
			// 点击立即报名按钮
			toSignUp(id) {
				this.$CheckRole("培训活动报名", async () => {
					let formData = new FormData();
					formData.append("id", id);
					const { code, msg } = await uploadFile(
						this,
						config.api.signUpTrainNotice,
						formData,
						"POST"
					);
					this.loading = false;
					if (code != "200") return this.$message.warning(msg);
					this.$message.success("申请报名成功，请您准时参加培训！");
					// this.getTrainNoticeList(); //更新列表数据（立即报名按钮变成已报名）
					this.notice.isApply = 1;
				})
			}
		}
	}
</script>

<style scoped>
	.noticeFrame {
		margin-bottom: 20px;
		border: 1px solid #eeeeee;
	}

	.noticeFrame:hover{
		cursor: pointer;
	}

	.noticeFrame .noticeName {
		text-align: left;
		font-size: 18px;
		font-weight: bold;
		margin-bottom: 10px;
		color: #333;
	}

	.noticeFrame .noticeMsg {
		text-align: left;
		padding: 20px 10px;
		font-size: 12px;
	}

	.noticeMsg .tip {
		color: #999;
	}

	.noticeFrame .noticeFooter {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 10px;
		border-top: 1px solid #eeeeee;
	}
	.in-apply {
		color: #045db9;
		font-size: 12px;
	}
	.noticeFrame .noticeFooter .noticeBtn {
		font-size: 14px;
		background-color: #f1f2f4;
		color: #045db9;
		padding: 5px 10px;
		border-radius: 3px;
		transition: all 0.2s ease 0s;
	}
	
	.noticeFrame .noticeFooter ._btn {
		font-size: 14px;
		background-color: #f1f2f4;
		color: #045db9;
		padding: 5px 10px;
		border-radius: 3px;
		transition: all 0.2s ease 0s;
		cursor: default;
	}

	.noticeFrame .noticeFooter .noticeBtn:hover {
		background-color: #045db9;
		color: #f1f2f4;
		cursor: pointer;
	}
</style>
